<extend name="Public:comment" />

<block name="title">购物车</block>

<block name="css">
	<link rel="stylesheet" href="/Application/Home/Common/css/base.css" type="text/css" />
	<link rel="stylesheet" href="/Application/Home/Common/css/shop_common.css" type="text/css" />
	<link rel="stylesheet" href="/Application/Home/Common/css/shop_header.css" type="text/css" />
	<link rel="stylesheet" href="/Application/Home/Common/css/shop_gouwuche.css" type="text/css" />
</block>

<block name="js">
	<script type="text/javascript" src="/Application/Home/Common/js/jquery.js" ></script>
    <script type="text/javascript" src="/Application/Home/Common/js/topNav.js" ></script>
    <script src="/Application/Home/Common/js/jquery-2.0.3.min.js" ></script>
    <script type="text/javascript">
    	$(function(){
    		$(".good_num_jian").click(function(){
    			var ind = $(".good_num_jian").index($(this));
    			var id = $(".good-item").eq(ind).data('id');
				var val = $(".good_nums").eq(ind).val();
				var price = $(".danjia").eq(ind).text();
				val--;
				if(val == 0){
					val=1
				}
				var costs = price*val;
				$(".good_nums").eq(ind).val(val);
				$(".xiaoji").eq(ind).text(costs);
				var sum = 0;
				for(let a=0;a<$(".xiaoji").length;a++){
					var xiaoji = $(".xiaoji").eq(a).text();
					sum += Number(xiaoji);
				}
				$("#good_zongjia").text(sum);
				$.ajax({
					type:"POST",
					url:"{:U('flow_ajax')}",
					data:{num:val,id:id},
					success:function(msg){

					}
				});
			});

			$(".good_num_jia").click(function(){
				var ind = $(".good_num_jia").index($(this));
    			var id = $(".good-item").eq(ind).data('id');
				var val = $(".good_nums").eq(ind).val();
				var price = $(".danjia").eq(ind).text();
				val++;
				var costs = price*val;
				$(".good_nums").eq(ind).val(val);
				$(".xiaoji").eq(ind).text(costs);
				var sum = 0;
				for(let a=0;a<$(".xiaoji").length;a++){
					var xiaoji = $(".xiaoji").eq(a).text();
					sum += Number(xiaoji);
				}
				$("#good_zongjia").text(sum);
				$.ajax({
					type:"POST",
					url:"{:U('flow_ajax')}",
					data:{num:val,id:id},
					success:function(msg){

					}
				});
			});

			$(".collect").click(function(){
				var ind = $(".collect").index($(this));
				var href = $(".collect").eq(ind).attr("href");
				var id = href.substr(22);
				$.ajax({
					type: "POST",
					url: "{:U('collect_add')}",
					data: {pid:id},
					success: function(msg){
						alert(msg.info);
					}
				});
			});

			$(".shop_good_delete").click(function(){
				var ind = $(".shop_good_delete").index($(this));
				var href = $(".shop_good_delete").eq(ind).attr('href');
				var id = href.substr(22);
				$.ajax({
					type: "POST",
					url: "{:U('flow_delete')}",
					data: {id:id},
					success: function(msg){
						alert(msg.info);
					}
				});
				$(".tr").eq(ind).remove();
			});
    	});
    </script>
</block>

<block name="shouye">
	<div id="shop_hd_menu_all_category" class="shop_hd_menu_all_category"><!-- 首页去掉 id="shop_hd_menu_all_category" 加上clsss shop_hd_menu_hover -->
</block>

<block name="content">
	<!-- 面包屑 注意首页没有 -->
	<div class="shop_hd_breadcrumb">
		<strong>当前位置：</strong>
		<span>
			<a href="">首页</a>&nbsp;›&nbsp;
			<a href="">我的商城</a>&nbsp;›&nbsp;
			<a href="">我的购物车</a>
		</span>
	</div>
	<div class="clear"></div>
	<!-- 面包屑 End -->

	<!-- Header End -->
	
	<!-- 购物车 Body -->
	<div class="shop_gwc_bd clearfix">
		<!-- 在具体实现的时候，根据情况选择其中一种情况 -->
		
		
		<!-- 购物车有商品 -->
		<div class="shop_gwc_bd_contents clearfix">
			<!-- 购物流程导航 -->
			<div class="shop_gwc_bd_contents_lc clearfix">
				<ul>
					<li class="step_a hover_a">确认购物清单</li>
					<li class="step_b">确认收货人资料及送货方式</li>
					<li class="step_c">购买完成</li>
				</ul>
			</div>
			<!-- 购物流程导航 End -->

			<!-- 购物车列表 -->
			<table>
				<thead>
					<tr>
						<th colspan="2"><span>商品</span></th>
						<th><span>单价(元)</span></th>
						<th><span>数量</span></th>
						<th><span>小计</span></th>
						<th><span>操作</span></th>
					</tr>
				</thead>
				<tbody>
					<foreach name="res" item="v">
						<tr class="tr good-item" data-id="{$v['id']}">
							<td class="gwc_list_pic"><a href=""><img src="/Uploads/{$v['pic']}" style="height:60px;"/></a></td>
							<td class="gwc_list_title" style="width:400px;"><a href="" style="font-size:14px;">{$v.content}</a></td>
							<td class="gwc_list_danjia" style="width:100px;"><span>￥<strong class="danjia">{$v.cost}</strong></span></td>
							<td class="gwc_list_shuliang">
							<span>
							<a class="good_num_jian this_good_nums" href="javascript:void(0);">-</a>
							<input type="text" value="{$v['num']}" class="good_nums" style="width:40px;"/>
							<a class="good_num_jia this_good_nums" href="javascript:void(0);">+</a>
							</span></td>
							<td class="gwc_list_xiaoji" style="width:80px;"><span>￥<strong class="xiaoji">{$v.costs}</strong></span></td>
							<td class="gwc_list_caozuo"><a href="javascript:void(0);id={$v['id']}" class="collect">收藏</a><a href="javascript:void(0);id={$v['id']}" class="shop_good_delete">删除</a></td>
						</tr>
					</foreach>

					
				</tbody>
				<tfoot>
					<tr>
						<td colspan="6">
							<div class="gwc_foot_zongjia">商品总价(不含运费)<span>￥<strong id="good_zongjia">{$sum}</strong></span></div>
							<div class="clear"></div>
							<div class="gwc_foot_links">
								<a href="{:U('Index/index')}" class="go">继续购物</a>
								<a href="{:U('Index/flow2')}" class="op">确认收货地址</a>
							</div>
						</td>
					</tr>
				</tfoot>
			</table>
			<!-- 购物车列表 End -->
		</div>
		<!-- 购物车有商品 end -->

	</div>
	<!-- 购物车 Body End -->
</block>